package com.zyy.joseata.interceptor.datasource;

import org.springframework.jdbc.datasource.AbstractDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author zhangyy
 */
public class JoSeataDataSourceProxy extends AbstractDataSource {

    private final DataSource targetDataSource;

    public JoSeataDataSourceProxy(DataSource targetDataSource) {
        this.targetDataSource = targetDataSource;
    }

    @Override
    public Connection getConnection() throws SQLException {
        Connection realConnection = targetDataSource.getConnection();
        return new JoSeataConnectionProxy(realConnection);
    }

    @Override
    public Connection getConnection(String username,String password) throws SQLException{
        Connection realConnection = targetDataSource.getConnection();
        return new JoSeataConnectionProxy(realConnection);
    }

}
